Page({
    data: {
      classCode: '',
      loading: false
    },
  
    onClassCodeChange(e) {
      this.setData({
        classCode: e.detail.toUpperCase()
      });
    },
  
    async handleJoin() {
      if (!this.data.classCode) {
        return wx.showToast({
          title: '请输入班级码',
          icon: 'none'
        });
      }
  
      this.setData({ loading: true });
  
      try {
        await api.joinClass({
          classCode: this.data.classCode
        });
  
        wx.showToast({
          title: '加入成功',
          icon: 'success'
        });
  
        wx.navigateBack();
      } catch (error) {
        wx.showToast({
          title: error.message || '加入失败',
          icon: 'none'
        });
      } finally {
        this.setData({ loading: false });
      }
    }
  });